package com.acwing.partition19;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/1/23 8:47
 */
public class AC1884COW {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int n = Integer.parseInt(reader.readLine());
        String s = reader.readLine();
        //如果当前字符是'C'：f[i][0]=f[i-1][0]+1,f[i][1]=f[i-1][1],f[i][2]=f[i-1][2]
        //如果当前字符是'O'：f[i][1]=f[i-1][1]+f[i-1][0],f[i][0]=f[i-1][0],f[i][2]=f[i-1][2]
        //如果当前字符是'W'：f[i][2]=f[i-1][2]+f[i-1][1].f[i][0]=f[i-1][0],f[i][1]=f[i-1][1]
        long c = 0, o = 0, w = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == 'C') c++;
            else if (s.charAt(i) == 'O') o += c;
            else if (s.charAt(i) == 'W') w += o;
        }
        writer.write(w + "\n");
        writer.flush();
    }
}
